
import sys, os, shutil, stat
import git

TEMP_DIR = './temp-repo'

def rmtree_error_handler(func, path, execinfo):
    os.chmod(path, stat.S_IWUSR)
    func(path)

def main():
    if len(sys.argv) != 2:
        print('number of arguments is incorrect')
        return
    
    remote_url = sys.argv[1]

    if os.path.exists(TEMP_DIR):
        shutil.rmtree(TEMP_DIR, onerror=rmtree_error_handler)

    os.mkdir(TEMP_DIR)
    os.chdir(TEMP_DIR)

    readme = open('readme.md', 'w')
    readme.close()

    repo = git.Repo.init(path='.')

    repo.git.add('.')
    repo.git.commit('-m', 'feat: 初始化仓库')

    repo.git.checkout('-b', 'develop')

    repo.git.remote('add', 'origin', remote_url)
    repo.git.push('-u', '--all', 'origin')

    print('remote repo [%s] initialized successfully' % remote_url)

if __name__ == "__main__":
    main()




